FROM fedora:34
MAINTAINER asaleh@redhat.com
ENV VERSION=5.7.3
ENV COMMIT=f20a3f86034670033aa5b6ce65229201b779ba4d
ENV SPECURL=https://gist.githubusercontent.com/AdamSaleh/1919b8ec41075e415613e033086a6054/raw/4795a74b9cff10e401119a4e74b1085498ad7d91/bodhi.spec
RUN  dnf -y install fedora-packager wget curl
RUN yum -y install rpm-build redhat-rpm-config make gcc git vi tar unzip rpmlint && yum clean all
RUN curl $SPECURL -o /tmp/bodhi.spec
RUN dnf -y builddep --spec /tmp/bodhi.spec
RUN useradd rpmbuild -u 5002 -g users -p rpmbuild
USER rpmbuild
ENV HOME /home/rpmbuild
WORKDIR /home/rpmbuild
RUN curl $SPECURL -o /home/rpmbuild/bodhi.spec
RUN mkdir -p /home/rpmbuild/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
RUN echo '%_topdir %{getenv:HOME}/rpmbuild' > /home/rpmbuild/.rpmmacros
RUN wget https://github.com/fedora-infra/bodhi/archive/${COMMIT}.tar.gz 
RUN mv ${COMMIT}.tar.gz /home/rpmbuild/rpmbuild/SOURCES/bodhi-${COMMIT}.tar.gz
RUN sed -i "s/891564724f08124c3272e2f16717b41fd9a56e78/${COMMIT}/g" /home/rpmbuild/bodhi.spec
RUN sed -i "s/5\.7\.1/${VERSION}/g" /home/rpmbuild/bodhi.spec
RUN rpmbuild --define "commit ${COMMIT}"  -ba /home/rpmbuild/bodhi.spec

FROM fedora:34

LABEL \
  name="bodhi-base" \
  vendor="Fedora Infrastructure" \
  license="MIT"
RUN curl -o /etc/yum.repos.d/infra-tags-stg.repo https://infrastructure.fedoraproject.org/infra/ansible/files/common/fedora-infra-tags-stg.repo

# While dnf has a --nodocs, it doesen't have a --docs...

RUN sed -i '/nodocs/d' /etc/dnf/dnf.conf
COPY --from=0 /home/rpmbuild/rpmbuild/RPMS /tmp/RPMS

RUN dnf install -y /tmp/RPMS/noarch/* python3-pyramid_sawing python3-gunicorn

# Set up krb5
RUN rm -f /etc/krb5.conf && \
    ln -sf /etc/bodhi/krb5.conf /etc/krb5.conf && \
    ln -sf /etc/keytabs/koji-keytab /etc/krb5.bodhi_bodhi{{ env_suffix }}.fedoraproject.org.keytab
ENV USER=openshift 
